package com.lcgroup.springdemo.demos.config;

import com.lcgroup.springdemo.demos.filter.MySecurityFilter0;
import com.lcgroup.springdemo.demos.filter.MySecurityFilter1;
import com.lcgroup.springdemo.demos.handler.GlobeExceptionHandler;
import com.lcgroup.springdemo.demos.filter.GlobeFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import javax.servlet.Filter;


@Configuration
public class FilterConfig implements WebMvcConfigurer {

    @Bean
    public FilterRegistrationBean<GlobeFilter> demoFilter0(GlobeExceptionHandler globeExceptionHandler) {
        GlobeFilter filter =  new GlobeFilter(globeExceptionHandler);
        FilterRegistrationBean<GlobeFilter> bean = new FilterRegistrationBean<>(filter);
        bean.addUrlPatterns("/exception/filter");
        return bean;
    }

    @Bean
    public FilterRegistrationBean<MySecurityFilter0> demoFilter1(MySecurityFilter0 filter) {
        FilterRegistrationBean<MySecurityFilter0> bean = new FilterRegistrationBean<>(filter);
        bean.setEnabled(false);
        return bean;
    }

    @Bean
    public FilterRegistrationBean<MySecurityFilter1> demoFilter2(MySecurityFilter1 filter) {
        FilterRegistrationBean<MySecurityFilter1> bean = new FilterRegistrationBean<>(filter);
        bean.setEnabled(false);
        return bean;
    }

}
